import request from '@/config/axios'
import { RetrieveIndexParams, RetrieveIndexDetailParams } from './types'
import { IndexItem, IndexValue } from '@/views/SysContent/types/dataindex'

export const RetrieveIndex = (params: RetrieveIndexParams): Promise<IResponse> => {
  return request.get({ url: '/v1/admin/dataindex/retrieve/', params })
}

export const UpdateIndex = async (data: IndexItem): Promise<IResponse> => {
  return request.put({ url: '/v1/admin/dataindex/update/', data })
}

export const CreateIndex = async (data: IndexItem): Promise<IResponse> => {
  return request.post({ url: '/v1/admin/dataindex/create/', data })
}

export const RetrieveIndexDetail = (prm: RetrieveIndexDetailParams): Promise<IResponse> => {
  return request.get({
    url: `/v1/admin/dataindex/${prm.index_id}/`,
    params: { page: prm.page, page_size: prm.page_size }
  })
}
export const UpdateIndexDetail = (
  index_id: number,
  data: Array<IndexValue>
): Promise<IResponse> => {
  return request.put({ url: `/v1/admin/dataindex/${index_id}/`, data })
}
export const CreateIndexDetail = (index_id: number, data: Array<{}>): Promise<IResponse> => {
  return request.post({ url: `/v1/admin/dataindex/${index_id}/`, data })
}
export const BrushIndexDetail = (index_id: number): Promise<IResponse> => {
  return request.delete({ url: `/v1/admin/dataindex/${index_id}/` })
}

export const RetrieveIndexExist = async (plat: string, plat_id: string) => {
  return request.get({ url: `/v1/admin/dataindex/exist/`, params: { plat, plat_id } })
}
